#!/bin/bash

if [[ 3 > 7 ]]; then
	echo "hehe"
else
	echo "yes"
fi

echo "======="
echo "for in 循环"
echo "for str in a\\'s b c d \"e f\" ; do "
for str in a\'s b c d "e f" ; do 
echo "->$str"
done

echo "======="
echo "c 语言风格的 for 循环"
echo "for (( i = 0; i < 10; i++ )); do"
for (( i = 0; i < 10; i++ )); do
	echo "for next = ${i}"
done


var1=0
while [[ $var1 -lt 10 ]]; do
	echo "while next ${var1}"
	# var1=$(expr $var1 + 1)
	var1=$[ $var1 + 1 ]
done

echo "9*9======="
i=1
j=1
line=""
while [[ i -lt 10 ]]; do
	j=1
	line=""
	until [[ j -eq 10 ]]; do
		if [[ j -le i ]]; then
			result=$(expr $i \* $j)
			resultStr="$j X $i = $result"
			line=${line}${resultStr}"\t"
		fi
		j=$(expr $j + 1)
	done
	echo -e ${line}
	i=$(expr $i + 1)
done


echo "======="
echo "循环处理文件数据"
IFS_OLD=$IFS
IFS=$'\n'
for line in $(tail /etc/passwd); do
	echo "LINE========${line}"
	IFS=:
	for word in $line; do
		if [[ $word == "*" ]]; then
			echo -e "word>>\*";
		else
			echo -e "word>>${word}"
		fi
	done
done
IFS=$IFS_OLD


echo "======="
echo "循环处理目录，并且使用重定向把文本内容写入到文件中"
for file in ~/* ~/Documents/*; do
	if [[ -d $file ]]; then
		echo "$file is Directory"
	else
		echo "$file is File"
	fi
done > output.txt


echo "======="
echo "查找可执行文件"
IFS=:
for pathDir in $PATH; do
	for bin in $pathDir/*; do
		if [[ -x $bin ]]; then
			echo $bin
		fi
	done
done




